package com.mtaite.study.mybatis.controller;

import com.mtaite.study.mybatis.entity.UserDO;
import com.mtaite.study.mybatis.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CustomerController {

    @Autowired
    private UserMapper customerMapper;

    @GetMapping("addUser")
    public UserDO addCustomer(@RequestParam("name") String name, @RequestParam("password") String password,@RequestParam("gender") String gender) {

        UserDO u=new UserDO();
        u.setId(Math.random()+"");
        u.setGender(gender);
        u.setName(name);
        u.setPassword(password);

        customerMapper.adduser(u);
        return u;
    }

    @GetMapping("findUser")
    public UserDO findCustomer(@RequestParam("name") String name, @RequestParam("password") String password) {
        UserDO u=new UserDO();
        u.setName(name);
        u.setPassword(password);

        return customerMapper.findByPwdAndname(u);
    }
}